home *** CD-ROM | disk | FTP | other *** search
- // SmallDesk © 1994 Reinder Verlinde
- //
- // Patches DisableItem, tests for call from Finder and right item,
- // calls EnableItem instead if match found.
- //
- // Detailed description:
- //
- // Init time:
- // Find the addresses for both 'DisableItem' and EnableItem'
- // Patch DisableItem
- //
- #include <Traps.h>
-
- #define FinderName 0x02E0
- #define CurApName 0x0910
- #define MenuList 0x0A1C
-
- void main( void)
- {
- asm
- {
- //
- // DetachResource called to make this code stay around in
- // the system heap after the init has run. The resource
- // is in the system heap and locked (its resource flags are
- // set like that)
- //
- // #pragma parameter __A0 RecoverHandle(__A0)
- move.l d0,a0
- dc.w _RecoverHandle
- // pascal void DetachResource(Handle theResource)
- Move.l a0,-(SP)
- dc.w _DetachResource
- //
- // Remember old values of EnableItem and DisableItem
- // We do not really need to be able to call 'EnableItem', but
- // calling EnableItem instead of DisableItem is way easier than
- // having to figure out what to do with the stack ourselves.
- // It also better reflects the way to do this with MacsBug.
- // (atba DisableItem ';sw pc A939;g')
- //
- move.w #_EnableItem,d0
- dc.w _GetToolTrapAddress
- lea @oldEnable,a1
- move.l a0,(a1)
-
- move.w #_DisableItem,d0
- dc.w _GetToolTrapAddress
- lea @oldDisable,a1
- move.l a0,(a1)
- //
- // Install our patch
- //
- lea @newDisable,a0
- move.w #_DisableItem,d0
- dc.w _SetToolTrapAddress
- //
- // and quit
- //
- rts
- oldEnable:
- dc.l 0x00000000
-
- oldDisable:
- dc.l 0x00000000
-
- ViewMenuHandle:
- dc.l 0x00000000
-
- newDisable:
- //
- // First we do a fast test. If this is the handle of the 'View menu'
- // we simply call EnableItem
- //
- lea @ViewMenuHandle,a0
- move.l (a0),d0
- cmp.l #0x00,d0
- beq.s @menu_not_yet_seen
- cmp.l 0x06(sp),d0
- beq.s @doEnable
-
- doDisable:
- move.l @oldDisable,a0
- jmp (a0)
-
- menu_not_yet_seen:
- //
- // Is this call done from within the Finder?
- //
- move.l #FinderName,a0
- move.l #CurApName,a1
-
- move.b (a0)+,d0
- cmp.b (a1)+,d0
- bne.s @doDisable
-
- again:
- move.b (a0)+,d1
- cmp.b (a1)+,d1
- bne.s @doDisable
- dbpl d0,@again
- //
- // We were called from the Finder. Is this the 'View' menu?
- // We simply look into the Menu Handle for the length byte
- // and first three characters of the menu title. If they are
- // 0x04, respectively 'Vie', we assume this is the View menu.
- //
- move.l 0x06(sp),a0
- move.l (a0),a0
- move.l 0x0E(a0),d0
- cmp.l #0x04566965,d0
- bne.s @doDisable
- //
- // We found the view menu. Remember its handle and do an
- // enable instead of a disable
- //
- move.l 0x06(sp),d0
- lea @ViewMenuHandle,a0
- move.l d0,(a0)
-
- doEnable:
- move.l @oldEnable,a0
- jmp (a0)
-
- }
- }
-